package com.tdzx.adapter;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.tdzx.R;
import com.tdzx.entity.Type;

public class CatoServiceTypeAdapter extends BaseAdapter {
	LayoutInflater factory;
	public static int selected = 0;
	private List<Type> serviceData = new ArrayList<Type>();
	
	public CatoServiceTypeAdapter(LayoutInflater factory) {
		this.factory = factory;
	}

	@Override
	public int getCount() {
		int size = 0;
		if(serviceData != null) {
			size = serviceData.size();
		}
		return size;
	}

	@Override
	public Object getItem(int position) {
		return serviceData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View conview, ViewGroup parent) {
		if(conview == null) {
			conview = factory.inflate(R.layout.list_servicetype_item_catagory, null);
		}
		TextView service_type = (TextView) conview.findViewById(R.id.service_type);
		service_type.setText(serviceData.get(position).getUplabel_name());
		ImageView line = (ImageView) conview.findViewById(R.id.line);
		
		ImageView catgoryImg = (ImageView) conview.findViewById(R.id.catgoryImg);
		if(position == 0) {
			catgoryImg.setImageResource(R.drawable.ic_category_0);
		} else if(position == 1) {
			catgoryImg.setImageResource(R.drawable.ic_category_10);
		} else if(position == 2) {
			catgoryImg.setImageResource(R.drawable.ic_category_30);
		} else if(position == 3) {
			catgoryImg.setImageResource(R.drawable.ic_category_80);
		} else if(position == 4) {
			catgoryImg.setImageResource(R.drawable.ic_category_20);
		} else if(position == 5) {
			catgoryImg.setImageResource(R.drawable.ic_category_60);
		} else if(position == 6) {
			catgoryImg.setImageResource(R.drawable.ic_category_50);
		} else if(position == 7) {
			catgoryImg.setImageResource(R.drawable.ic_category_45);
		} else if(position == 8) {
			catgoryImg.setImageResource(R.drawable.ic_category_55);
		}
		
		if(position == selected) {
			conview.setBackgroundResource(R.color.serviceChosed);
			line.setVisibility(View.VISIBLE);
		} else {
//			conview.setBackgroundResource(R.color.pop_condicition_type);
			conview.setBackgroundResource(R.drawable.cat_list_selector);
			
			line.setVisibility(View.INVISIBLE);
		}
		return conview;
	}

	public List<Type> getServiceData() {
		return serviceData;
	}

	public void setServiceData(List<Type> serviceData) {
//		this.serviceData = serviceData;
		this.serviceData.addAll(serviceData);
	}

}
